#!/bin/bash

VERSION=$1
if [ -z $VERSION ] ; then
	echo "No Version Lebel Provided... Exiting."
	exit 1
fi

LABEL=$2
if [ -z $LABEL ] ; then
        echo "No Name LABEL Provided... Exiting."
        exit 1
fi

if [ -e ./arch/x86/boot/bzImage ] ; then 
	install --verbose --mode 644 --owner root --group root ./arch/x86/boot/bzImage  /boot/vmlinuz-$VERSION-$LABEL.physix.x86_64
	if [ $? -ne 0 ] ; then 
		echo "Kernel Image Not found"
		exit 1
	fi
fi

if [ -e ./System.map ] ; then
	install --verbose --mode 644 --owner root --group root ./System.map  /boot/System.map-$VERSION-$LABEL
	if [ $? -ne 0 ] ; then
	       echo "System.map Not found" 
	       exit 1
	fi
fi

if [ -e .config ] ; then
	install --verbose --mode 644 --owner root --group root .config  /boot/config-$VERSION-$LABEL.physix.x86_64
	if [ $? -ne 0 ] ; then 
		echo "Failed config install" 
		exit 1
	fi
fi

mkinitrd --force /boot/initrd-$VERSION-$LABEL.physix.x86_64 $VERSION
if [ $? -ne 0 ] ; then
	echo "mkinitrd failed"
	exit 1
fi

echo "menuentry \"Physix GNU/Linux (systemd), Linux $VERSION $LABEL-physix\" {
        linux /vmlinuz-$VERSION-$LABEL.physix.x86_64 root=/dev/mapper/physix-root ro
        initrd /initrd-$VERSION-$LABEL.physix.x86_64
}" >> /boot/grub/grub.cfg


